package com.guangzhi.weijianzhi.adapter;

import java.util.ArrayList;

import com.guangzhi.weijianzhi.R;
import com.guangzhi.weijianzhi.utils.Misc;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

public class MainBannerPagerAdapter extends PagerAdapter {


	private ArrayList<String> datas = new ArrayList<String>();
	private Context context;
	public MainBannerPagerAdapter(ArrayList<String> list,Context con) {
		this.datas =list;
		this.context = con;
	}

	
	
	@Override
	public int getItemPosition(Object object) {
		return super.getItemPosition(object);
	}
	
	@Override
	public int getCount() {
		return Integer.MAX_VALUE;
	}
	
	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		final int location =position % datas.size();
		final ImageView view = (ImageView) View.inflate(context,R.layout.main_viewpage_image,null);
		container.addView(view);
		try {
			final String url = datas.get(location);
			ImageLoader.getInstance().displayImage(url,view);
			
			view.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Misc.alert(location+"");
				}
			});
			
		} catch (Exception e) {
		}
		return view;
	}
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View)object);
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}
}